package cn.wolfcode.luowowo.search.query;

import cn.wolfcode.luowowo.common.query.QueryObject;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

@Setter
@Getter
public class SearchQueryObject extends QueryObject{

    private int type = -1;  //默认查全部

    private Long destId = -1L;

    //条件类型
    public static final int CONDITION_TYPR_ABROAD = 0;  //国外
    public static final int CONDITION_TYPR_UN_ABROAD = 1;  //国内
    public static final int CONDITION_TYPR_THEME = 2;  //主题

    //es中分页对象
    public Pageable getPageable(){
        return PageRequest.of(super.getCurrentPage()-1, super.getPageSize());
    }

    //带排序的分页对象
    public Pageable getSortPageable(Sort sort){
        return PageRequest.of(super.getCurrentPage(), super.getPageSize(), sort);
    }

    /**
     * @param field 排序字段
     * @param orderType 排序类型： desc asc
     * @return
     */
    public Pageable customizeSortPageable(String field, String orderType ){
        Sort sort = new Sort(Sort.Direction.valueOf(orderType), field);
        return PageRequest.of(super.getCurrentPage(), super.getPageSize(), sort);
    }

    public Pageable customizeSortPageable(String field, Sort.Direction  orderType){
        Sort sort = new Sort(orderType, field);
        return PageRequest.of(super.getCurrentPage(), super.getPageSize(), sort);
    }

}
